package com.roads.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.roads.common.annotation.Log;
import com.roads.common.core.controller.BaseController;
import com.roads.common.core.domain.AjaxResult;
import com.roads.common.enums.BusinessType;
import com.roads.system.domain.SysReport;
import com.roads.system.service.ISysReportService;
import com.roads.common.utils.poi.ExcelUtils;
import com.roads.common.core.page.TableDataInfo;

/**
 * 系统报Controller
 * 
 * @author nhp
 * @date 2022-06-08
 */
@RestController
@RequestMapping("/system/report")
public class SysReportController extends BaseController {

    @Autowired
    private ISysReportService service;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:report:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysReport model) {
        startPage();
        List<SysReport> list = service.selectModelList(model);
        return getDataTable(list);
    }

    /**
     * 导出
     */
    @PreAuthorize("@ss.hasPermi('system:report:export')")
    @Log(title = "系统报表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysReport model) {
        List<SysReport> list = service.selectModelList(model);
        ExcelUtils<SysReport> util = new ExcelUtils<SysReport>(SysReport.class);
        return util.exportExcel(list, "系统报数据");
    }

    /**
     * 获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:report:query')")
    @GetMapping(value = "/{reportUuid}")
    public AjaxResult getInfo(@PathVariable("reportUuid") String reportUuid) {
        return AjaxResult.success(service.getModelById(reportUuid));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('system:report:add')")
    @Log(title = "系统报表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysReport model) {
        return toAjax(service.insert(model));
    }

    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:report:edit')")
    @Log(title = "系统报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysReport model) {
        return toAjax(service.update(model));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:report:remove')")
    @Log(title = "系统报表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(service.deleteByIds(ids));
    }
}
